//爬取html上的信息：

const HOST = 'http://web.itheima.com/'
const axios = require('axios')
const cheerio = require('cheerio')
const download = require('download')

axios.get('http://web.itheima.com/teacher.html#ajavaee').then(res=>{
  
    let $ = cheerio.load(res.data) //这个可以认为是全局变量
    // let imgs = []
    // $(".tea_main .tea_con .tea_txt ul li img").each((index,item)=>{
    //     console.log(HOST+$(item).attr('src'))
    //     imgs.push(HOST+$(item).attr('src'))
    // })
    let imgs = ([]).map.call($(".tea_main .tea_con .tea_txt ul li img"),(item)=>encodeURI(HOST+$(item).attr('src')))

    Promise.all(imgs.map(item=>download(item,'dist'))).then(()=>{
        console.log("file downloaded!")
    })
})